var Mistasapp = window.Mistasapp = Ember.Application.create();

/* Order and include as you please. */
require('scripts/controllers/*');
require('scripts/store');
require('scripts/models/*');
require('scripts/routes/*');
require('scripts/components/*');
require('scripts/views/*');
require('scripts/router');
/*document.addEventListener("deviceready", onDeviceReady, false);
google.maps.event.addDomListener(window, 'load', initialize);
var geo = new google.maps.Geocoder();


function initialize() {
    var myOptions = {
        center: new google.maps.LatLng(34.88866, -7.4665777),
        zoom: 5,
        scrollwheel: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        // Add controls
        mapTypeControl: true,
        scaleControl: true,
        overviewMapControl: true,
        overviewMapControlOptions: {
            opened: true
        }
    };
    map = new google.maps.Map(document.getElementById('map'), myOptions);

    var myCoordinates = [
        new google.maps.LatLng(37.189314,-7.553787),
        new google.maps.LatLng(37.153886,-7.536621),
        new google.maps.LatLng(37.175364,-7.465897),
        new google.maps.LatLng(37.201210,-7.487526)
    ];
    var polyOptions = {
        path: myCoordinates,
        strokeColor: "#56f756",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        clickable:false

    }
    var it = new google.maps.Polygon(polyOptions);
    it.setMap(map);


    // Define the LatLng coordinates for the polygon's path.

    marker = new google.maps.Marker({
        animation: google.maps.Animation.DROP,
        draggable: true
    });
    google.maps.event.addListener(map, "click", function(e) {
        clicked(e.latLng, map,it);
    });
    google.maps.event.addListener(marker, 'dragend', function(e) {
        clicked(e.latLng, map,it);
    });

}




function addmarker(position) {


    map.panTo(position);
    map.setZoom(14);
    map.setCenter(position);
    marker.setPosition(position);
    marker.setMap(map);


}

function onDeviceReady() {
    var options = {maximumAge: 0, timeout: 60000, enableHighAccuracy: true}
    navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
}

function onSuccess(position) {
    addmarker(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));

    var element = document.getElementById('geolocation');
    var geo = new google.maps.Geocoder();
    element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
        'Longitude: ' + position.coords.longitude + '<br />' +
        '<hr />' + element.innerHTML;

    var ps = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    geo.geocode({'latLng': ps}, function(results, status) {
        if (status != google.maps.GeocoderStatus.OK) {
            alert("reverse geocoder failed to find an address for " + position.toUrlValue());
        }
        else {
            address = results[0].formatted_address;
            var element = document.getElementById('geolocation');
            element.innerHTML = address + '\nMargem de erro: ' + position.coords.accuracy;

        }

    });


}

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: ' + error.code + '\n' +
        'message: ' + error.message + '\n');
}
function clicked(position, map,it) {
    if ( google.maps.geometry.poly.containsLocation(position, it)==false) {
        alert("esta fora de area de servico");
        //TODO remove marker
    }else{
        geo.geocode({'latLng': position}, function (results, status) {
            if (status != google.maps.GeocoderStatus.OK) {
                alert("reverse geocoder failed to find an address for " + position.toUrlValue());
            }
            else {
                address = results[0].formatted_address;
                var element = document.getElementById('geolocation');
                element.innerHTML = address
            }
        });
        addmarker(position);

    }
}*/

var posts = [{
    id: '1',
    title: "Rails is Omakase",
    author: {name: "d2h"},
    date: new Date('12-27-2012'),
    excerpt: "There are lots of à la carte software environments in this world. Places where in order to eat, you must first carefully look over the menu of options to order exactly what you want.",
    body: "I want this for my ORM, I want that for my template language, and let's finish it off with this routing library. Of course, you're going to have to know what you want, and you'll rarely have your horizon expanded if you always order the same thing, but there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is omakase."
}, {
    id: '2',
    title: "The Parley Letter",
    author: {name: "d2h"},
    date: new Date('12-24-2012'),
    excerpt: "My [appearance on the Ruby Rogues podcast](http://rubyrogues.com/056-rr-david-heinemeier-hansson/) recently came up for discussion again on the private Parley mailing list.",
    b